package 力扣日常刷题.木22二月.第01天206;

import 力扣日常刷题.TreeNode;

/**
 * @author 帅小伙
 * @date 2022/2/6
 * @description
 */
public class Demo12JZ树的子结构 {


    public boolean isSubStructure(TreeNode A, TreeNode B) {
        return (A != null && B != null)
                && (recur(A, B)
                || isSubStructure(A.left, B)
                || isSubStructure(A.right, B));
    }

    boolean recur(TreeNode A, TreeNode B) {
        if (B == null) return true;
        if (A == null || A.val != B.val) return false;
        return recur(A.left, B.left) && recur(A.right, B.right);
    }


}
